#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kernel_stat.h>
#include <linux/platform_device.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>

struct device *dev;
int version = 159;
int  brightness = 1024;

static DEVICE_INT_ATTR(version,S_IWUSR | S_IRUGO,version);
static DEVICE_INT_ATTR(brightness,S_IWUSR | S_IRUGO,brightness);

//属性结构体数组最后一项必须以NULL结尾。
static struct attribute *gpio_attrs[] = {
		&dev_attr_version.attr.attr,
		&dev_attr_brightness.attr.attr,
NULL };

static const struct attribute_group gpio_attr_grp = {
		.attrs = gpio_attrs,
//		.name     = "mygroup",
};

int myprobe(struct platform_device *pdev) {
	int ret;
	dev = &pdev->dev;
	ret = sysfs_create_group(&dev->kobj, &gpio_attr_grp);
	pr_info("myplatformdriver myprobe \n");
	return 0;
}

int myremove(struct platform_device *pdev) {
	pr_info("myplatformdriver myremove \n");
	sysfs_remove_group(&dev->kobj, &gpio_attr_grp);
	return 0;
}

struct of_device_id my_of_match_table =
		{ .compatible = "my_platform_device_003", };

struct platform_driver my_platform_driver = { .driver =
		{ .of_match_table = &my_of_match_table, .name = "my-platform-driver",
				.owner = THIS_MODULE, }, .probe = myprobe, .remove = myremove, };

module_platform_driver(my_platform_driver);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Andy");
MODULE_DESCRIPTION("andy one-key driver");
MODULE_ALIAS("one-key");
